{extend name="light-year/layout/master/detail" /}

{block name="title"}文章管理{/block}
{block name="page-title"}文章{/block}

{block name="content"}
<input name="article_id" class="form-control" type="hidden" value="{if $detail}{$detail->article_id}{/if}" />
<div class="form-group">
    <label><span class="text-danger">*</span> 所属文章分类：</label>
    <div class="form-controls">
        <select name="category_id" class="form-control" required>
            <option value="0"> 请选择文章分类 </option>
            {if !empty($category_list)}
                {foreach $category_list as $category}
                    <option value="{$category->category_id}" {if $detail && $detail->category_id == $category->category_id}selected{/if} >{$category->category_name}</option>
                {/foreach}
            {/if}
        </select>
    </div>
    <small class="help-block">
        <i class="mdi mdi-information"></i>
        请选择文章所属的分类
    </small>
</div>
<div class="form-group">
    <label><span class="text-danger">*</span> 文章名称：</label>
    <input type="text" class="form-control" name="article_title" value="{if $detail}{$detail->article_title}{/if}" placeholder="输入文章名称" />
    <small class="help-block">
        <i class="mdi mdi-information"></i>
        唯一标识
    </small>
</div>
{if !empty($article_labels)}
    <?php
        $label_ids = empty($detail) ? [] : array_column($detail->labels->toArray(), 'label_id', 'label_id');
    ?>
    <div class="form-group">
        <label>
            设置文章关联标签：
        </label>
        <div class="clearfix">
            {foreach $article_labels as $label}
                <label class="lyear-radio radio-inline radio-primary">
                    <input type="radio" name="label_ids[]" value="{$label->label_id}"
                           {if isset($label_ids[$label->label_id])}checked{/if}
                        >
                    <span>{$label->label_name}</span>
                </label>
            {/foreach}
        </div>
    </div>
{/if}
<div class="form-group">
    <label>
        封面：
    </label>
    <div>
        <input type="hidden" name="article_cover" value="{if $detail}{$detail->article_cover}{/if}"/>
        <div id="article_cover">
            <div id="article_cover_filePicker"><i class="icon-cloud-upload"></i></i> 选择单张图片</div>
        </div>
    </div>
    <small class="help-block">
        <i class="mdi mdi-information"></i>
        文章的封面图
    </small>
</div>
<div class="form-group">
    <label> 关键词：</label>
    <textarea class="form-control" rows="5" name="article_keywords" placeholder="请输入关键词" >{if $detail}{$detail->article_keywords}{/if}</textarea>
</div>
<div class="form-group">
    <label> 描述：</label>
    <textarea class="form-control" rows="5" name="article_description" placeholder="请输入描述" >{if $detail}{$detail->article_description}{/if}</textarea>
</div>
<div class="form-group">
    <label> 文章内容：</label>
    <div id="test-editor" name="article_content">
        <textarea style="display:none;" name="article_content">{if $detail}{$detail->article_content}{/if}</textarea>
    </div>
</div>
<div class="form-group">
    <label> 文章来源：</label>
    <input type="url" class="form-control" name="article_origin" value="{if $detail}{$detail->article_origin}{/if}" placeholder="输入文章来源" />
</div>
<div class="form-group">
    <label> 文章来源作者：</label>
    <input type="text" class="form-control" name="article_author" value="{if $detail}{$detail->article_author}{/if}" placeholder="输入文章来源作者" />
</div>
<div class="form-group">
    <label> 排序：</label>
    <input type="number" class="form-control" name="article_sort" value="{if $detail}{$detail->article_sort}{else/}0{/if}" placeholder="输入排序" />
    <small class="help-block">
        <i class="mdi mdi-information"></i>
        从小到大，升序
    </small>
</div>
<div class="form-group">
    <label>
        是否推荐：
    </label>
    <div class="clearfix">
        <label class="lyear-radio radio-inline radio-primary">
            <input type="radio" name="is_recommend" value="1" {if (empty($detail) || $detail->is_recommend === 1) }checked{/if}><span>是</span>
        </label>
        <label class="lyear-radio radio-inline radio-primary">
            <input type="radio" name="is_recommend" value="0" {if (empty($detail) || $detail->is_recommend === 0) }checked{/if}><span>否</span>
        </label>
    </div>
</div>
<div class="form-group">
    <label>
        是否置顶：
    </label>
    <div class="clearfix">
        <label class="lyear-radio radio-inline radio-primary">
            <input type="radio" name="set_top" value="1" {if (empty($detail) || $detail->set_top === 1) }checked{/if}><span>是</span>
        </label>
        <label class="lyear-radio radio-inline radio-primary">
            <input type="radio" name="set_top" value="0" {if (empty($detail) || $detail->set_top === 0) }checked{/if}><span>否</span>
        </label>
    </div>
</div>
<div class="form-group">
    <label>
        是否启用：
    </label>
    <div class="clearfix">
        <label class="lyear-radio radio-inline radio-primary">
            <input type="radio" name="is_public" value="0" {if (empty($detail) || $detail->is_public === 0) }checked{/if}><span>禁用</span>
        </label>
        <label class="lyear-radio radio-inline radio-primary">
            <input type="radio" name="is_public" value="1" {if (empty($detail) || $detail->is_public === 1) }checked{/if}><span>启用</span>
        </label>
    </div>
</div>
<div class="form-group">
    <button type="submit" class="btn btn-primary ajax-post" target-form="add-form">确 定</button>
    <button type="button" class="btn btn-default" onclick="javascript:history.back(-1);return false;">返 回</button>
</div>
{/block}

{block name="script"}
{include file="light-year/layout:plugins/webuploader" /}
{include file="light-year/layout:plugins/editormd" /}

<script type="text/javascript">
    window.onload = function () {
        closeLayerLoading(closeAllLayer);

        // 图片上传组件
        webUploaderImgs('#article_cover_filePicker', '', '#article_cover', 'input[name=article_cover]', {'img_limit':1, 'single_graph_type':1});

        // 详情图片渲染（使用这种方式，可以共用图片上传限制等功能）
        let detail = JSON.parse('{:html_get_res_from_admin($detail)}');
        if (detail && !isEmpty(detail.article_cover)){
            $('#article_cover').append(webUploaderImgHtml(detail.article_cover, 'input[name=article_cover]', $('#article_cover_filePicker').attr('span-class')));
        }
    }
</script>
{/block}